#include "unit.h"
#include "D3DGraphics.h"
#include "physics.h"

bool unit_t::in_collision( const unit_t &other_unit )
{
	// Two circles colliding:
	//  if sqrt( |x1-x2|^2 + |y1-y2|^2 ) < sum of radiuses -> return true

	int dist = body.radius + other_unit.body.radius;
	float x_diff = state.s.x - other_unit.state.s.x;
	float y_diff = state.s.y - other_unit.state.s.y;

	if(sqrt( x_diff*x_diff + y_diff*y_diff ) < dist) return true;
	return false;
}

void unit_t::draw( D3DGraphics &gfx, const rectangle_screen_t &view_rect )
{
	// Note that this is very slow. We have to use sprites instead.
	// The put pixel function used by drawdisc also checks every pixel to see if it is outside the screen.
	// This is god aweful slow, so again we have to use sprites.

	gfx.DrawDisc( state.s.x - view_rect.top_left.x, 
					state.s.y - view_rect.top_left.y, 
					body.radius, 
					color.r,color.g,color.b );
}
